/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jili.ubert.test;

import com.jili.ubert.code.server2client.Price;
import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.avis.client.Elvin;
import org.avis.client.Notification;

/**
 *
 * @author ChengJili
 */
public class SimPrice {

    private static final Log log = LogFactory.getLog(SimPrice.class);
    private static Elvin elvin = null;

    static {
        String elvinUri = System.getProperty("elvin", "elvin://localhost");
        try {
            elvin = new Elvin(elvinUri);
            log.info("启动连接avis router:" + elvinUri);
            //System.out.println("启动连接avis router:"+elvinUri);
            elvin.closeOnExit();
        } catch (Exception e) {
            log.info(e);
        }
    }

    public static void main(String[] args) throws UnknownHostException, SocketException, IOException {
        //   TradeNeworderCopy order = new TradeNeworderCopy();
        SimPrice my = new SimPrice();
        my.testSHprice();
        my.testHKprice();
        my.testSZprice();
        my.testSZprice();
    }

    private void testSZprice() {
        Price price = generalPrice1("000001", "A");
        try {
            SendMsg(price.EnCode(price), "C", "A");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testHKprice() {
        Price price = generalPrice("600000", "S");
        try {
            SendMsg(price.EnCode(price), "C", "S");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testSHprice() {
        Price price = generalPrice("00001", "H");
        try {
            SendMsg(price.EnCode(price), "H", "H");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testHKprice1() {
        Price price = generalPrice1("600000", "S");
        try {
            SendMsg(price.EnCode(price), "C", "S");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testSHprice1() {
        Price price = generalPrice1("00001", "H");
        try {
            SendMsg(price.EnCode(price), "H", "H");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testHKprice2() {
        Price price = generalPrice2("600000", "S");
        try {
            SendMsg(price.EnCode(price), "C", "S");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private void testSHprice2() {
        Price price = generalPrice2("00001", "H");
        try {
            SendMsg(price.EnCode(price), "H", "H");
        } catch (IOException ex) {
            log.error(ex);
        }
    }

    private Price generalPrice(String obj, String mk) {
        Price price = new Price();
        price.setLastPrice((float) 14.9);
        price.setLastQty(100);

        price.setAskQty1(100);
        price.setAskQty2(100);
        price.setAskQty3(100);
        price.setAskQty4(100);
        price.setAskQty5(100);

        price.setAskPrice1((float) 14.8);
        price.setAskPrice2((float) 14.7);
        price.setAskPrice3((float) 14.6);
        price.setAskPrice4((float) 14.5);
        price.setAskPrice5((float) 14.4);

        price.setBidPrice1((float) 15.0);
        price.setBidPrice2((float) 15.1);
        price.setBidPrice3((float) 15.2);
        price.setBidPrice4((float) 15.3);
        price.setBidPrice5((float) 15.4);

        price.setBidQty1(100);
        price.setBidQty2(100);
        price.setBidQty3(100);
        price.setBidQty4(100);
        price.setBidQty5(100);
        price.setMaketCode(mk);
        price.setObj(obj);
        price.setRegionID("C");
        price.seteName("PFYH");
        return price;
    }

    private Price generalPrice1(String obj, String mk) {
        Price price = new Price();
        price.setLastPrice((float) 14.9);
        price.setLastQty(100);

        price.setAskQty1(100);
        price.setAskQty2(100);

        price.setAskPrice1((float) 14.8);
        price.setAskPrice2((float) 14.7);

        price.setBidPrice1((float) 15.0);
        price.setBidPrice2((float) 15.1);
        price.setBidPrice3((float) 15.2);
        price.setBidPrice4((float) 15.3);
        price.setBidPrice5((float) 15.4);

        price.setBidQty1(100);
        price.setBidQty2(100);
        price.setBidQty3(100);
        price.setBidQty4(100);
        price.setBidQty5(100);
        price.setMaketCode(mk);
        price.setObj(obj);
        price.setRegionID("C");
        price.seteName("PFYH");
        return price;
    }

    private Price generalPrice2(String obj, String mk) {
        Price price = new Price();
        price.setLastPrice((float) 14.9);
        price.setLastQty(100);

        price.setAskQty1(100);
        price.setAskQty2(100);
        price.setAskQty3(100);
        price.setAskQty4(100);
        price.setAskQty5(100);

        price.setAskPrice1((float) 14.8);
        price.setAskPrice2((float) 14.7);
        price.setAskPrice3((float) 14.6);
        price.setAskPrice4((float) 14.5);
        price.setAskPrice5((float) 14.4);

        price.setBidPrice1((float) 15.0);

        price.setBidQty1(100);

        price.setMaketCode(mk);
        price.setObj(obj);
        price.setRegionID("C");
        price.seteName("PFYH");
        return price;
    }

    private void SendMsg(byte[] dd, String regionID, String mk) {
        //发送委托
        Notification msg = new Notification();
        msg.set("Title", "Price");
        msg.set("RegionID", regionID);
        msg.set("MaketCode", mk);
        msg.set("Data", dd);
        //发送结束
        try {
            elvin.send(msg);
        } catch (IOException ex) {
            log.error(ex);
        }
    }
}
